var Login = function () {
    
    return {
        //主要功能模块
        init: function () {       	
           $('.login-form').validate({
	            errorElement: 'label', //容器默认输入错误消息
	            errorClass: 'help-inline', // 默认的输入错误消息类
	            focusInvalid: false, // 不要输入无效焦点
	            rules: {
	                username: {
	                    required: true,
	                    minlength:11
	                },
	                password: {
	                    required: true,
	                    minlength:6
	                },
	                remember: {
	                    required: false
	                }
	            },
	            messages: {
	                username: {
	                    required: "用户手机号码错误."
	                },
	                password: {
	                    required: "密码输入错误."
	                }
	            },

	            invalidHandler: function (event, validator) { //显示在表单提交错误警报   
	                $('.alert-error', $('.login-form')).show();
	            },

	            highlight: function (element) { //标出错误的输入 
	                $(element)
	                    .closest('.control-group').addClass('error'); //设置错误类对照组
	            },

	            success: function (label) {
	                label.closest('.control-group').removeClass('error');
	                label.remove();
	            },

	            errorPlacement: function (error, element) {
	                error.addClass('help-small no-left-padding').insertAfter(element.closest('.input-icon'));
	            },

	          submitHandler: function (form) { 
	            }
	        });

	        $('.login-form input').keypress(function (e) {
	   
	            if (e.which == 13) {
	                if ($('.login-form').validate().form()) {
	                    window.location.href = "";
	                }
	                return false;
	            }
	        });

	        $('.forget-form').validate({
	            errorElement: 'label', //容器默认输入错误消息
	            errorClass: 'help-inline', //默认的输入错误消息类 
	            focusInvalid: false, //不要最后无效输入焦点 
	            ignore: "",
	            rules: {
	                email: {
	                    required: true,
	                    email: true
	                }
	            },

	            messages: {
	                email: {
	                    required: "邮箱输入有误."
	                }
	            },

	            invalidHandler: function (event, validator) { //display error alert on form submit   

	            },

	            highlight: function (element) { // hightlight error inputs
	                $(element)
	                    .closest('.control-group').addClass('error'); // set error class to the control group
	            },

	            success: function (label) {
	                label.closest('.control-group').removeClass('error');
	                label.remove();
	            },

	            errorPlacement: function (error, element) {
	                error.addClass('help-small no-left-padding').insertAfter(element.closest('.input-icon'));
	            },

	            submitHandler: function (form) {
	                window.location.href = "";
	            }
	        });

	        $('.forget-form input').keypress(function (e) {
	            if (e.which == 13) {
	                if ($('.forget-form').validate().form()) {
	                    window.location.href = "";
	                }
	                return false;
	            }
	        });

	        jQuery('#forget-password').click(function () {
	            jQuery('.login-form').hide();
	            jQuery('.forget-form').show();
	        });

	        jQuery('#back-btn').click(function () {
	            jQuery('.login-form').show();
	            jQuery('.forget-form').hide();
	        });

	        $('.register-form').validate({
	            errorElement: 'label', 
	            errorClass: 'help-inline', 
	            focusInvalid: false, // do not focus the last invalid input
	            ignore: "",
	            rules: {
	                username: {
	                    required: true,
	                    minlength:11
	                },
	                password:{
	                    required: true,
	                    minlength:6
	                },
	                rpassword: {
	                	required: true,
	                    minlength:6
	                },
	                email: {	                	
	                    required: true                   
	                },
	                tnc: {
	                    required:"请先同意服务条款"
	                }
	            },

	            messages: { //自定义消息为单选按钮和复选框
	                tnc: {
	                    required: "请先同意服务条款."
	                }
	            },

	            invalidHandler: function (event, validator) { //显示在表单提交错误警报
	            },

	            highlight: function (element) { // hightlight error inputs
	                $(element)
	                    .closest('.control-group').addClass('error'); // set error class to the control group
	            },

	            success: function (label) {
	                label.closest('.control-group').removeClass('error');
	                label.remove();
	            },

	            errorPlacement: function (error, element) {
	                if (element.attr("name") == "tnc") { // insert checkbox errors after the container                  
	                    error.addClass('help-small no-left-padding').insertAfter($('#register_tnc_error'));
	                } else {
	                    error.addClass('help-small no-left-padding').insertAfter(element.closest('.input-icon'));
	                }
	            },

	            submitHandler: function (form) {
	                window.location.href = "";
	            }
	        });

	        jQuery('#register-btn').click(function () {
	            jQuery('.login-form').hide();
	            jQuery('.register-form').show();
	        });

	        jQuery('#register-back-btn').click(function () {
	            jQuery('.login-form').show();
	            jQuery('.register-form').hide();
	        });
        }

    };

}();